package com.starsoft.trade.job;

import java.util.Date;
import java.util.List;

import org.quartz.JobExecutionContext;

import com.starsoft.frame.base.bean.BaseJobLog;
import com.starsoft.frame.base.job.AbstractJob;
import com.starsoft.frame.util.SpringContext;
import com.starsoft.trade.bean.TradeAcount;
import com.starsoft.trade.service.AcountStatusService;
import com.starsoft.trade.service.TradeAcountService;

public class AcountStatusUpdateJob extends AbstractJob {

	@Override
	public void run(JobExecutionContext context, BaseJobLog jobLog) {
		TradeAcountService tradeAcountService = SpringContext.getBean(TradeAcountService.class);
		AcountStatusService acountStatusService = SpringContext.getBean(AcountStatusService.class);
		
		List<TradeAcount> tradeAcounts = tradeAcountService.getAll();
		Date now = new Date();
		for(TradeAcount tradeAcount : tradeAcounts){
			if(tradeAcount.getEndDate()!=null && now.after(tradeAcount.getEndDate())){
				continue;
			}
			acountStatusService.updateStatus(tradeAcount.getAcountId(), now, now);
		}
	}

}
